/*
* Copyright @ 2014 com.iflysse.trains
* manger_v2.0 上午10:48:55
* All right reserved.
*
*/
package com.iflysse.service;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import com.iflysse.dao.RoleInfoDao;
import com.iflysse.pojo.RoleInfo;
import com.iflysse.utils.MySessionFactory;
import com.iflysse.utils.PagerBean;

/**
 * @desc: manger_v2.0
 * @author: wql
 * @createTime: 2014年11月20日 上午10:48:55
 * @history:
 * @version: v1.0
 */
public class RoleInfoService {

	/**
	*
	* @author: wql
	* @createTime: 2014年11月20日 上午10:51:44
	* @history:
	* @param pager
	* @return PagerBean<RoleInfo>
	*/
	private SqlSessionFactory sf;

	public RoleInfoService() {
		sf = MySessionFactory.getSessionFactory();
	}
	
	//edit by chen
	public List<RoleInfo> findAllRole(){
		SqlSession session = sf.openSession();
		RoleInfoDao dao = (RoleInfoDao) session.getMapper(RoleInfoDao.class);
		List<RoleInfo> list = dao.findAllRole();
		session.close();
		return list;
	}
	
	public PagerBean<RoleInfo> findRolePager(PagerBean<RoleInfo> pager) {
		SqlSession session = sf.openSession();
		try {
			RoleInfoDao dao = (RoleInfoDao) session
					.getMapper(RoleInfoDao.class);
			List<RoleInfo> RoleList = dao.findRolePager(pager);
			long total = dao.findRoleTotal(pager);
			pager.setRows(RoleList);
			pager.setTotal(total);
		} finally {
			session.close();
		}
		return pager;
	}

	/**
	*
	* @author: wql
	* @createTime: 2014年11月20日 下午2:57:37
	* @history:
	* @param Role void
	*/
	public void updatetRole(RoleInfo Role) {
		SqlSession session =sf.openSession();
		RoleInfoDao dao=(RoleInfoDao)session.getMapper(RoleInfoDao.class);
		RoleInfo co=Role;		
		dao.updateRole(co);
		session.commit();
		session.close();		
	}

	/**
	*
	* @author: wql
	* @createTime: 2014年11月20日 下午2:58:42
	* @history:
	* @param Role void
	*/
	public void insertRole(RoleInfo Role) {
		SqlSession session =sf.openSession();
		RoleInfoDao dao=session.getMapper(RoleInfoDao.class);
		RoleInfo co=Role;
		dao.insertRole(co);
		session.commit();
		session.close();		
	}

	/**
	*
	* @author: wql
	* @createTime: 2014年11月20日 下午3:00:19
	* @history:
	* @param Roleid
	* @return RoleInfo
	*/
	public RoleInfo findRoleById(int Roleid) {
		SqlSession session = sf.openSession();
		RoleInfo Role=null;
		try {
			RoleInfoDao dao = (RoleInfoDao) session.getMapper(RoleInfoDao.class);
			Role = dao.findRoleById(Roleid);
		} finally {
			session.close();
		}
		return Role;
	}

	/**
	*
	* @author: wql
	* @createTime: 2014年11月20日 下午3:02:52
	* @history:
	* @param Roleid void
	*/
	public void delRoleById(int Roleid) {
		SqlSession session = sf.openSession();
		try {
			RoleInfoDao dao = (RoleInfoDao) session
					.getMapper(RoleInfoDao.class);
			dao.delById(Roleid);
			session.commit();
		} finally {
			session.close();
		}
		
	}

	/**
	*
	* @author: wql
	* @createTime: 2014年11月20日 下午4:19:35
	* @history:
	* @param pager
	* @return PagerBean<RoleInfo>
	*/
	public List<RoleInfo> findRoleByName(String name) {
		SqlSession session = sf.openSession();
		List<RoleInfo> Role=null;
		try {
			RoleInfoDao dao = (RoleInfoDao) session.getMapper(RoleInfoDao.class);
			Role = dao.findRoleByName(name);
		} finally {
			session.close();
		}
		return Role;
	}

	
	
}
